home *** CD-ROM | disk | FTP | other *** search
- Path: nntp-server.caltech.edu!news
- From: Xuhua Li <xuhua@cco.caltech.edu>
- Newsgroups: comp.lang.c++
- Subject: How to simulate EOF from the keyboard in Visual C++ 4.0, CTRL+Z doesn't work well
- Date: Sun, 17 Mar 1996 17:15:19 -0800
- Organization: California Institute of Technology, Pasadena
- Message-ID: <314CB927.22A3@cco.caltech.edu>
- NNTP-Posting-Host: xuhua-ppp.caltech.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=gb2312
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
- CC: cpp-students@zib-berlin.de
-
- The title says everything. When I try to simulate the EOF from the
- keyboard in Visual C++ with CTRL+Z, it doesn't work. CTRL+Z just kill
- the running program. I am running windows 95.
- Please try the following simple program from <<C++ Primer Plus>>:
-
- Program #1
- // textin3.cpp -- reading chars to end of file
- #include <iostream.h>
- int main(void)
- {
- char ch;
- int count = 0;
-
- while (cin.get(ch)) // cin.get(ch) is 0 on EOF
- {
- cout << ch;
- count++;
- }
- cout << count << " characters read\n";
- return 0;
- }
-
- Program #2
-
- // ifelse.cpp -- using the if else statement
- #include <iostream.h>
- int main(void)
- {
- char ch;
-
- cout << "Type, and I shall repeat.\n";
- while (cin.get(ch))
- {
- if (ch == '\n')
- cout << ch; // done if newline
- else
- cout << ++ch; // done otherwise
- }
- // try ch + 1 instead of ++ch for interesting effect
- cout << "Please excuse the slight confusion.\n";
- return 0;
- }
-
- You assistance will be highly appreciated.
-